#include <iostream> 
#include <string> 
#include <unordered_map> 
#include <vector> 
 
bool is_prime(int number) { 
    if (number <= 1) return false; 
    if (number <= 3) return true; 
 
    if (number % 2 == 0 || number % 3 == 0) return false; 
 
    for (int i = 5; i * i <= number; i += 6) { 
        if (number % i == 0 || number % (i + 2) == 0) 
            return false; 
    } 
    return true; 
} 
 
int main() { 
    std::unordered_map<std::string, int> words_to_numbers = { 
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4}, 
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9} 
    }; 
 
    std::string word; 
    std::vector<int> digits; 
 
    for (int i = 0; i < 3; ++i) { 
        std::cin >> word; 
        if (words_to_numbers.find(word) == words_to_numbers.end()) { 
            std::cout << "Wrong input"; 
            return 0; 
        } 
        digits.push_back(words_to_numbers[word]); 
    } 
 
    int number = digits[0] * 100 + digits[1] * 10 + digits[2]; 
 
    // Find the closest prime number 
    int lower_prime = number, upper_prime = number; 
    while (!is_prime(lower_prime)) --lower_prime; 
    while (!is_prime(upper_prime)) ++upper_prime; 
 
    if (number - lower_prime <= upper_prime - number) { 
        std::cout << lower_prime; 
    } else { 
        std::cout << upper_prime; 
    } 
 
    return 0; 
}